import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.io.HttpConnection;
import javax.microedition.io.StreamConnection;


/**
 * 
 * With a given connection, the connectionDialer have to talk with the server
 * in order to get aivalable information.
 * A message is created with this information.
 * 
 * 
 * @author Mathieu Maret
 */
public abstract class ConnectionDialer {
	

	/**
	 * Close all the connection established 
	 */
	public abstract void close();

	/**
	 * When a connection is established, this connection is given to the deal
	 * method in order to get aivalable information
	 * 
	 * 
	 * @return Message A Message which will contain the informations transmitted 
	 */
	public abstract Message deal(StreamConnection conn);
	/*public  Message deal(StreamConnection conn){
		DataInputStream in = null;
		DataOutputStream out = null; 
		boolean error = false;
		try {
			in = conn.openDataInputStream();
			out = conn.openDataOutputStream();
		} catch (IOException e) {
			error = true;
			e.printStackTrace();
		}
		if(!error){
		return deal(in,out);
		}else{
			Message m = new Message("Cannot open input or output data stream");
			m.setType(Message.ERROR);
			return m;
		}
	}
	public  Message deal(HttpConnection conn){
		DataInputStream in = null;
		DataOutputStream out = null; 
		boolean error = false;
		try {
			in = conn.openDataInputStream();
			out = conn.openDataOutputStream();
		} catch (IOException e) {
			error = true;
			e.printStackTrace();
		}
		if(!error){
		return deal(in,out);
		}else{
			Message m = new Message("Cannot open input or output data stream");
			m.setType(Message.ERROR);
			return m;
		}
	}
	
	public Message deal(DataInputStream in, DataOutputStream out){
		return new Message("");
	}*/

}
